package com.corecloud.controller.sys;

import com.corecloud.service.sms.ValidateCodeProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
public class ImageCodeController {

    @Autowired
    private Map<String, ValidateCodeProcessor> validateCodeProcessors;

    /**
     * 获取短信验证码请求
     * @param request
     * @param response
     * @param type：请求参数
     * @return
     * @throws Exception
     */
    @GetMapping("/code/{type}")
    public Integer getCode(HttpServletRequest request, HttpServletResponse response, @PathVariable String type) throws Exception {
        String codeName = type + ValidateCodeProcessor.CODE_PROCESSOR;
        return validateCodeProcessors.get(codeName).create(new ServletWebRequest(request, response));
    }
}
